package tianrun.ziguan.api.calculate.config.service.expression.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import tianrun.ziguan.api.calculate.config.dao.TExpressionMapper;
import tianrun.ziguan.api.calculate.config.dto.request.ExpressionVO;
import tianrun.ziguan.api.calculate.config.entity.TExpression;
import tianrun.ziguan.api.calculate.config.service.expression.ITExpressionService;
import tianrun.ziguan.api.calculate.config.utils.CollectionUtil;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * @author zhaoqi
 */
@Service
public class TExpressionServiceImpl extends ServiceImpl<TExpressionMapper, TExpression> implements ITExpressionService {

    @Override
    public List<ExpressionVO> listVOByInstanceIds(Set<Long> ids,String tableName) {
        if (CollectionUtil.isEmpty(ids)) {
            return Collections.emptyList();
        }
        return baseMapper.listByInstanceIds(ids,tableName);
    }

    @Override
    public List<ExpressionVO> listVOByModuleIds(Set<Long> ids,String tableName) {
        if (CollectionUtil.isEmpty(ids)) {
            return Collections.emptyList();
        }
        return baseMapper.listByModuleIds(ids,tableName);
    }

    @Override
    public List<ExpressionVO> listVOByTemplateIds(Set<Long> ids,String tableName) {
        if (CollectionUtil.isEmpty(ids)) {
            return Collections.emptyList();
        }
        return baseMapper.listByTemplateIds(ids,tableName);
    }

    @Override
    public List<TExpression> querySyncListByInstanceIds(Set<Long> ids,String tableName) {
        if (CollectionUtil.isEmpty(ids)) {
            return Collections.emptyList();
        }
        return baseMapper.querySyncListByInstanceIds(ids,tableName);
    }

    @Override
    public List<TExpression> listByInstanceIds(Set<Long> ids,String tableName) {
        if (CollectionUtil.isEmpty(ids)) {
            return Collections.emptyList();
        }
        return list(Wrappers.<TExpression>lambdaQuery().eq(TExpression::getIsValid, true).in(TExpression::getRelationId, ids).eq(TExpression::getRelationTable, tableName));
    }
}
